package com.coder520.user.controller;

import com.coder520.user.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * Created by vern on 2017/9/13.
 */

@Controller
@RequestMapping("user")
public class UserController {

    /**
     * 用户登录成功跳转个人后台页面
     * @return
     */
    @RequestMapping("/home")
    public String user(){
        return "home";
    }

    /**
     * 获取登录用户信息
     * @param session
     * @return
     */
    @RequestMapping("/userinfo")
    @ResponseBody
    public User getUserInfo(HttpSession session){
     User user= (User) session.getAttribute("userinfo");
        return user;
    }

    /**
     * 退出登录
     * @param session
     * @return
     */
    @RequestMapping("logout")
    public String logout(HttpSession session){
        session.invalidate();
        return "login";
    }
}
